package lab02.test24;

import org.omg.CORBA.DATA_CONVERSION;

import java.util.Calendar;
import java.util.Date;
import java.util.Scanner;

/**
 * Created by 邱雅婷 on 2017/10/30.
 */
public class test {
    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        StringBuffer year1 = new StringBuffer();
        StringBuffer year2 = new StringBuffer();
        StringBuffer month1 = new StringBuffer();
        StringBuffer month2 = new StringBuffer();
        StringBuffer day1 = new StringBuffer();
        StringBuffer day2 = new StringBuffer();

        System.out.println("请输入两个日期");
        String scanner1 = scanner.next();
        String scanner2 = scanner.next();
        for (int i = 4; i<8;i++) {
            year1.append(scanner1.charAt(i)) ;
            year2.append(scanner2.charAt(i));
        }


        for (int i = 6;i <10 ;i++){
            month1.append(scanner1.charAt(i));
            month2.append(scanner2.charAt(i));
        }

        for (int i = 19;i<29;i++){
            day1.append(scanner1.charAt(i));
            day2.append(scanner2.charAt(i));
        }
        int year1number = Integer.parseInt(String.valueOf(year1));
        int year2number = Integer.parseInt(String.valueOf(year2));
        int month1number =Integer.parseInt(String.valueOf(month1));
        int month2number =Integer.parseInt(String.valueOf(month2));
        int day1number =Integer.parseInt(String.valueOf(day1));
        int day2number =Integer.parseInt(String.valueOf(day2));


        Date date1 =new Date(year1number,month1number,day1number);
        Date date2 =new Date(year2number,month2number,day2number);
        Calendar datea = Calendar.getInstance();
        Calendar dateb = Calendar.getInstance();
        datea.setTime(date1);
        dateb.setTime(date2);
        datea.add(Calendar.YEAR,-1900);
        datea.add(Calendar.MONTH,-1);
        dateb.add(Calendar.YEAR,-1900);
        dateb.add(Calendar.MONTH,-1);

        System.out.println(datea.getTime());
        System.out.println(dateb.getTime());
        //分别得到两个时间的毫秒数 
        long s1 = datea.getTimeInMillis();
        long s2 = dateb.getTimeInMillis();
        long time = s1 - s2;
        long sl=datea.getTimeInMillis();



        System.out.println("相差的天数为："+Math.abs(time)/(1000*60*60*24));
    }
}
